package nowcode

func getLongestPalindrome(s string) int {
	if s == "" {
		return 0
	}

	dp := make([][]bool, len(s))
	for i := range dp {
		dp[i] = make([]bool, len(s))
		for j := range dp[i] {
			dp[i][j] = true
		}
	}

	res := 1

	for col := 0; col < len(s); col++ {
		for row := 0; row < col; row++ {
			if s[col] != s[row] {
				dp[row][col] = false
			} else {
				dp[row][col] = dp[row+1][col-1]
				if dp[row][col] {
					if col-row+1 > res {
						res = col - row + 1
					}
				}
			}
		}
	}
	return res
}
